<%-- 
    Document   : edit.jsp
    Created on : 22.11.2014, 12:53:58
    Author     : David Katuscak, 359273
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>  

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><fmt:message key="edit" /></title>
    </head>
    <body>
        <div class="container">
            <c:if test="${null == customer}">
                <img src="<c:url value="/resources/pictures/error.png" />" title="<fmt:message key="customer.notFound" />" />
                <b><fmt:message key="customer.notfound" /></b>
            </c:if>
            <c:if test="${null != customer}">
                <h2><fmt:message key="customer.editCustomer" /> <c:out value="${customer.firstName}"/> <c:out value="${customer.lastName}"/></h2>

                <c:url var="saveUrl" value="/customer/edit" />
                <form:form method="POST" action="${saveUrl}" class="form-horizontal" modelAttribute="customer" commandName="customer">
                    <form:hidden path="id" />

                    <spring:bind path="firstName">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="firstName" class="control-label col-sm-2"><fmt:message key="customer.firstname" />:</form:label>
                                <div class="col-sm-10">
                                <form:input path="firstName" class="form-control"/>
                            </div>
                            <form:errors path="firstName" class="control-label col-sm-8"  />
                        </div>
                    </spring:bind>

                    <spring:bind path="lastName">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="lastName" class="control-label col-sm-2"><fmt:message key="customer.lastname" />:</form:label>
                                <div class="col-sm-10">
                                <form:input path="lastName" class="form-control"/>
                            </div>
                            <form:errors path="lastName" class="control-label col-sm-8"  />
                        </div>
                    </spring:bind>

                    <div class="form-group">
                        <form:label path="email" class="control-label col-sm-2"><fmt:message key="customer.email" />:</form:label>
                            <div class="col-sm-10">
                            <form:input path="email" class="form-control" readonly="true"/>
                        </div>
                    </div>

                    <spring:bind path="phone">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="phone" class="control-label col-sm-2"><fmt:message key="customer.phone" />:</form:label>
                                <div class="col-sm-10">
                                <form:input path="phone" class="form-control"/>
                            </div>
                            <form:errors path="phone" class="control-label col-sm-8"  />
                        </div>
                    </spring:bind>

                    <spring:bind path="street">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="street" class="control-label col-sm-2"><fmt:message key="customer.street" />:</form:label>
                                <div class="col-sm-10">
                                <form:input path="street" class="form-control"/>
                            </div>
                            <form:errors path="street" class="control-label col-sm-8"  />
                        </div>
                    </spring:bind>

                    <spring:bind path="city">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="city" class="control-label col-sm-2"><fmt:message key="customer.city" />:</form:label>
                                <div class="col-sm-10">
                                <form:input path="city" class="form-control"/>
                            </div>
                            <form:errors path="city" class="control-label col-sm-8"  />
                        </div>
                    </spring:bind>

                    <spring:bind path="zipCode">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="zipCode" class="control-label col-sm-2"><fmt:message key="customer.zipcode" />:</form:label>
                                <div class="col-sm-10">
                                <form:input path="zipCode" class="form-control"/>
                            </div>
                            <form:errors path="zipCode" class="control-label col-sm-8"  />
                        </div>
                    </spring:bind>

                    <spring:bind path="country">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="country" class="control-label col-sm-2"><fmt:message key="customer.country" />:</form:label>
                                <div class="col-sm-10">
                                <form:input path="country" class="form-control"/>
                            </div>
                            <form:errors path="country" class="control-label col-sm-8"  />
                        </div>
                    </spring:bind>

                    <div class="form-group">
                        <form:label path="customerType" class="control-label col-sm-2"><fmt:message key="customer.type" />:</form:label>
                            <div class="col-sm-10">
                            <form:input path="customerType" class="form-control" readonly="true"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <form:label path="vatNumber" class="control-label col-sm-2"><fmt:message key="customer.vat" />:</form:label>
                            <div class="col-sm-10">
                            <form:input path="vatNumber" class="form-control" readonly="true"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <form:label path="companyNumber" class="control-label col-sm-2"><fmt:message key="customer.companynumber" />:</form:label>
                            <div class="col-sm-10">
                            <form:input path="companyNumber" class="form-control" readonly="true"/>
                        </div>
                    </div>


                    <div class="form-group">        
                        <div class="col-sm-offset-2 col-sm-9">
                            <button type="submit" class="btn btn-default"><fmt:message key="save" /></button>
                            <a href="<c:url value="/customer/detail/${customer.id}" />" onclick="return confirm('<fmt:message key="cancel.confirm" />')"><fmt:message key="cancelChanges" /></a>
                        </div>
                    </div>

                </form:form>
            </c:if>

        </div>
    </body>
</html>
